package com.zr.daoImpl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import com.zr.dao.cxkcselectDaocy;
import com.zr.util.JDBCUtil;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

public class cxkcselectDaoImplcy implements cxkcselectDaocy {

	@Override
	public JSONArray getcxkcselect(int uid) {
		JSONArray js=new JSONArray();
		StringBuffer sql=new StringBuffer();
		sql.append(" SELECT course.cname,s_c.score,course.place FROM user");
		sql.append(" INNER JOIN s_c ON");
		sql.append(" user.sid=s_c.sid");
		sql.append(" INNER JOIN course ON");
		sql.append(" s_c.cid=course.cid");
		sql.append(" INNER JOIN student ON");
		sql.append(" student.sid=s_c.sid");
		sql.append(" WHERE uid=?");
		Connection con=JDBCUtil.getConnection();
		try {
			PreparedStatement pst=con.prepareStatement(sql.toString());
			pst.setInt(1, uid);
			ResultSet rs=pst.executeQuery();
			while(rs.next()){
				JSONObject p =new JSONObject();
				p.put("code", rs.getString("place"));
				p.put("name", rs.getString("cname"));
				p.put("price", rs.getString("score"));
				js.add(p);
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		return js;
	}

}
